<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input id="addressVal" type="text" />
    <button onclick="getPosition()">打卡</button>
    <div width="width: 200px;height: 200px;background: red;" id="allmap"></div>
</body>

</html>
<!-- <script src="./js/jquery.js"></script> -->
<script src="https://cdn.staticfile.org/jquery/3.7.1/jquery.js"></script>
<script type="text/javascript"
    src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=8GZt3SW34y29pdO74Qp5RQLxNzrr1CDp"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"> </script>

<script>
    var vConsole = new VConsole();
    var map = new BMapGL.Map("allmap");
    var lng = null;
    var lat = null;

    function getPosition() {
        var geolocation = new BMapGL.Geolocation();
        geolocation.getCurrentPosition(function (r) {
            var lng = r.point.lng;
            var lat = r.point.lat;
            console.log(lng, lat, '经纬度')
            var point = new BMapGL.Point(lng, lat); //用所定位的经纬度查找所在地省市街道等信息
            console.log(point, 'point')
            var gc = new BMapGL.Geocoder();
            // 百度地图API功能
            gc.getLocation(point, function (rs) {
                if (rs) {
                    var addComp = rs.addressComponents;
                    var site = "";
                    if (addComp.city) {
                        site += addComp.city;
                    }
                    if (addComp.district) {
                        site += addComp.district;
                    }
                    if (rs.surroundingPois[0].title) {
                        site += rs.surroundingPois[0].title;
                    }
                    if ("" == site) {
                        site = mLongitude + ",  " + mLatitude;
                    }
                    console.log(site, 'site')
                    $("#addressVal").val(site);

                }
            });
        })


    }
</script>

<style>
    html,
    body {
        height: 100%;
    }

    #allmalp {
        width: 100px;
        height: 100px;
    }
</style>